View on GitHub

csc263

Notes for CSC263 - Data Structures and Analysis

Back to index

Disjoint Sets

Operations

Let $\sigma$ be the procedure of $n - 1$ unions and $m \geq n$ finds

Naive implementations

Linked List

Augmented Linked List

Forest (tree-like)

Weighted Union

To do union, make root of smaller tree point to root of larger tree

Lemma

With weighted union, any tree $T$ of height $h$ created during the execution of $\sigma$ has $\vert T\vert \geq 2^h$

Proof.

Base case:

If $h = 0$, then the tree has $1 = 2^0$ node

Inductive step:

Suppose lemma holds for some $h \geq 0$.

To construct a tree of height $h+1$, we make the root of a tree $A$ of height $h$ point to the root of a bigger tree $B$ (because we are using weighted union)

By IH, $\vert A\vert \geq 2^h$

By WU rule, $\vert B\vert \geq \vert A\vert \geq 2^h$

Then resulting tree has number of nodes $\vert A\vert + \vert B\vert \geq 2 (2^h) = 2^{h + 1}$

Path compression

Before:

find(S, x) traverses from x to root

After:

image-20200214005653612


History: 25 years after publication of weighted union + path compression implementation, proof that $\sigma$ takes $\Theta(m \cdot \alpha(m, n))$ time using WU+PC was finally completed (where $\alpha$ is inverse Ackerman function).

The Ackerman function grows ridiculously quickly so $\alpha$ grows ridiculously slowly, so for all reasonable (read: physically possible) intents, $\sigma$ runs in linear time.